#include <stdio.h>
#include <stdlib.h>
#include <flgrCoreData.h>
#include <flgrCoreDataIO.h>
#include <flgrCoreCopy.h>
#include <flgrCoreVector.h>
#include <flgrCoreNhbManage.h>
#include "../macro.h"

  
#define FLGR_IMPORT1D_LIST_DATA_VAL(dtype)			\
  dtype *list_data;						\
  dtype *list_nhb;						\
  int *list_x;							\
  int *sz = (int*) box->size;					\
  int i,k;							\
								\
  for(k=0 ; k<box->spp ; k++) {					\
    sz[k] = size;						\
    list_data = (dtype*) box->list_data_val[k];			\
    list_nhb = (dtype*) box->list_nhb_val[k];			\
    list_x = (int*) box->list_coord_x[k];			\
								\
    for(i=0 ; i<sz[k] ; i++) {					\
      list_x[i] = list_coord_x[i*box->spp+k];			\
      list_nhb[i] = raw_nhb_val[i*box->spp+k];			\
      list_data[i] = raw_data_val[i*box->spp+k];		\
    }								\
  }								\
  

void flgr1d_import_list_data_val_fgBIT(FLGR_NhbBox1D *box, fgBIT *raw_data_val, fgBIT *raw_nhb_val,
				       int *list_coord_x, int size) {
  FLGR_IMPORT1D_LIST_DATA_VAL(fgBIT);
}
void flgr1d_import_list_data_val_fgUINT8(FLGR_NhbBox1D *box, fgUINT8 *raw_data_val, fgUINT8 *raw_nhb_val,
				       int *list_coord_x, int size) {
  FLGR_IMPORT1D_LIST_DATA_VAL(fgUINT8);
}
void flgr1d_import_list_data_val_fgUINT16(FLGR_NhbBox1D *box, fgUINT16 *raw_data_val, fgUINT16 *raw_nhb_val,
				       int *list_coord_x, int size) {
  FLGR_IMPORT1D_LIST_DATA_VAL(fgUINT16);
}
void flgr1d_import_list_data_val_fgUINT32(FLGR_NhbBox1D *box, fgUINT32 *raw_data_val, fgUINT32 *raw_nhb_val,
				       int *list_coord_x, int size) {
  FLGR_IMPORT1D_LIST_DATA_VAL(fgUINT32);
}
void flgr1d_import_list_data_val_fgINT8(FLGR_NhbBox1D *box, fgINT8 *raw_data_val, fgINT8 *raw_nhb_val,
				       int *list_coord_x, int size) {
  FLGR_IMPORT1D_LIST_DATA_VAL(fgINT8);
}
void flgr1d_import_list_data_val_fgINT16(FLGR_NhbBox1D *box, fgINT16 *raw_data_val, fgINT16 *raw_nhb_val,
					 int *list_coord_x, int size) {
  FLGR_IMPORT1D_LIST_DATA_VAL(fgINT16);
}
void flgr1d_import_list_data_val_fgINT32(FLGR_NhbBox1D *box, fgINT32 *raw_data_val, fgINT32 *raw_nhb_val,
					 int *list_coord_x, int size) {
  FLGR_IMPORT1D_LIST_DATA_VAL(fgINT32);
}
void flgr1d_import_list_data_val_fgFLOAT32(FLGR_NhbBox1D *box, fgFLOAT32 *raw_data_val, fgFLOAT32 *raw_nhb_val,
					   int *list_coord_x, int size) {
  FLGR_IMPORT1D_LIST_DATA_VAL(fgFLOAT32);
}
void flgr1d_import_list_data_val_fgFLOAT64(FLGR_NhbBox1D *box, fgFLOAT64 *raw_data_val, fgFLOAT64 *raw_nhb_val,
					   int *list_coord_x, int size) {
  FLGR_IMPORT1D_LIST_DATA_VAL(fgFLOAT64);
}

 
#define FLGR_IMPORT2D_LIST_DATA_VAL(dtype)			\
  dtype *list_data_val;						\
  dtype *list_nhb_val;						\
  int *list_x;							\
  int *list_y;							\
  int *sz = (int*) box->size;					\
  int i,k;							\
								\
								\
  for(k=0 ; k<box->spp ; k++) {					\
    sz[k] = size;						\
								\
    list_data_val = (dtype*) box->list_data_val[k];		\
    list_nhb_val = (dtype*) box->list_nhb_val[k];		\
    list_x = (int*) box->list_coord_x[k];			\
    list_y = (int*) box->list_coord_y[k];			\
								\
    for(i=0 ; i<sz[k] ; i++) {					\
      list_y[i] = list_coord_y[i*box->spp+k];			\
      list_x[i] = list_coord_x[i*box->spp+k];			\
      list_nhb_val[i] = raw_nhb_val[i*box->spp+k];		\
      list_data_val[i] = raw_data_val[i*box->spp+k];		\
    }								\
  }								\
  

void flgr2d_import_list_data_val_fgBIT(FLGR_NhbBox2D *box, fgBIT *raw_data_val, fgBIT *raw_nhb_val,
				       int *list_coord_x, int *list_coord_y, int size) {
  FLGR_IMPORT2D_LIST_DATA_VAL(fgBIT);
}
void flgr2d_import_list_data_val_fgUINT8(FLGR_NhbBox2D *box, fgUINT8 *raw_data_val, fgUINT8 *raw_nhb_val,
				       int *list_coord_x, int *list_coord_y, int size) {
  FLGR_IMPORT2D_LIST_DATA_VAL(fgUINT8);
}
void flgr2d_import_list_data_val_fgUINT16(FLGR_NhbBox2D *box, fgUINT16 *raw_data_val, fgUINT16 *raw_nhb_val,
				       int *list_coord_x, int *list_coord_y, int size) {
  FLGR_IMPORT2D_LIST_DATA_VAL(fgUINT16);
}
void flgr2d_import_list_data_val_fgUINT32(FLGR_NhbBox2D *box, fgUINT32 *raw_data_val, fgUINT32 *raw_nhb_val,
				       int *list_coord_x, int *list_coord_y, int size) {
  FLGR_IMPORT2D_LIST_DATA_VAL(fgUINT32);
}
void flgr2d_import_list_data_val_fgINT8(FLGR_NhbBox2D *box, fgINT8 *raw_data_val, fgINT8 *raw_nhb_val,
				       int *list_coord_x, int *list_coord_y, int size) {
  FLGR_IMPORT2D_LIST_DATA_VAL(fgINT8);
}
void flgr2d_import_list_data_val_fgINT16(FLGR_NhbBox2D *box, fgINT16 *raw_data_val, fgINT16 *raw_nhb_val,
				       int *list_coord_x, int *list_coord_y, int size) {
  FLGR_IMPORT2D_LIST_DATA_VAL(fgINT16);
}
void flgr2d_import_list_data_val_fgINT32(FLGR_NhbBox2D *box, fgINT32 *raw_data_val, fgINT32 *raw_nhb_val,
				       int *list_coord_x, int *list_coord_y, int size) {
  FLGR_IMPORT2D_LIST_DATA_VAL(fgINT32);
}
void flgr2d_import_list_data_val_fgFLOAT32(FLGR_NhbBox2D *box, fgFLOAT32 *raw_data_val, fgFLOAT32 *raw_nhb_val,
				       int *list_coord_x, int *list_coord_y, int size) {
  FLGR_IMPORT2D_LIST_DATA_VAL(fgFLOAT32);
}
void flgr2d_import_list_data_val_fgFLOAT64(FLGR_NhbBox2D *box, fgFLOAT64 *raw_data_val, fgFLOAT64 *raw_nhb_val,
				       int *list_coord_x, int *list_coord_y, int size) {
  FLGR_IMPORT2D_LIST_DATA_VAL(fgFLOAT64);
}


/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr_rec_open types
/////////////////////////////////////////////////////////////////////////
#define tstNhb_Extract1d(dtype)						\
									\
  dtype rawsrc[] = {0,1,1,0,1,1,0,1,1,1,0};				\
									\
  int poslst[]   = {3,4,5,6};						\
  dtype pixlst[] = {0,1,1,0};						\
  dtype nhblst[] = {1,1,1,1};						\
									\
									\
  FLGR_Data1D *datsrc, *nhb;						\
  FLGR_NhbBox1D *cont, *contref;					\
  FLGR_Ret ret;								\
									\
  nhb     = flgr1d_create_neighborhood(7,1,flgr_get_type_from_string(#dtype), \
				       FLGR_LINE);			\
  datsrc  = flgr1d_create_##dtype(11,1,FLGR_NO_SHAPE);			\
  cont    = flgr1d_create_neighbor_box(nhb);				\
  contref = flgr1d_create_neighbor_box(nhb);				\
									\
  flgr1d_import_raw_ptr(datsrc,rawsrc);					\
									\
  flgr1d_get_data_vector(nhb,(nhb->length)>>1,contref->center_nhb_val);	\
  flgr1d_get_data_vector(datsrc,0,contref->center_data_val);		\
  contref->center_coord_x = 0;						\
  flgr1d_import_list_data_val_##dtype(contref,pixlst,nhblst,poslst,4);	\
  									\
  ret = flgr1d_get_neighborhood(cont,datsrc,nhb,0);			\
									\
  check_and_display_box1d(contref,cont,ret);				\
  									\
  flgr1d_destroy(datsrc);						\
  flgr1d_destroy(nhb);							\
  flgr1d_destroy_neighbor_box(contref);					\
  flgr1d_destroy_neighbor_box(cont);					\
									\
  return 1


int testnhb_extract1d_fgBIT(void) {
  tstNhb_Extract1d(fgBIT);
}
int testnhb_extract1d_fgUINT8(void) {
  tstNhb_Extract1d(fgUINT8);
}
int testnhb_extract1d_fgUINT16(void) {
  tstNhb_Extract1d(fgUINT16);
}
int testnhb_extract1d_fgUINT32(void) {
  tstNhb_Extract1d(fgUINT32);
}
int testnhb_extract1d_fgINT8(void) {
  tstNhb_Extract1d(fgINT8);
}
int testnhb_extract1d_fgINT16(void) {
  tstNhb_Extract1d(fgINT16);
}
int testnhb_extract1d_fgINT32(void) {
  tstNhb_Extract1d(fgINT32);
}
int testnhb_extract1d_fgFLOAT32(void) {
  tstNhb_Extract1d(fgFLOAT32);
}
int testnhb_extract1d_fgFLOAT64(void) {
  tstNhb_Extract1d(fgFLOAT64);
}






/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr_rec_open types
/////////////////////////////////////////////////////////////////////////
#define tstNhb_Extract2d(dtype)						\
									\
  dtype rawsrc[]={105,115, 28, 41, 41, 48, 54, 57, 62, 70,		\
		  72, 76, 75, 76, 76, 78, 75, 77, 78, 76,		\
		  75, 79, 77, 76, 77, 73, 71, 64, 62, 55,		\
		  50, 44, 42, 32,123,112,100, 88, 82, 73,		\
		  73, 76, 76, 81, 85, 86, 90, 90, 93, 92,		\
		  91, 96, 96,100, 96, 98, 98, 97,102, 99,		\
		  98, 96, 99,102, 98, 93,100, 99, 94, 96,		\
		  94, 90, 88, 87, 88, 88, 85, 87, 35,  5};		\
									\
  int rowlst[]   = {3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6};			\
  int collst[]   = {3,4,5,6,3,4,5,6,3,4,5,6,3,4,5,6};			\
  dtype pixlst[] = {105,115,28,41,72,76,75,76,75,79,77,76,50,44,42,32};	\
  dtype nhblst[] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};			\
									\
									\
  FLGR_Data2D *imgsrc, *nhb;						\
  FLGR_NhbBox2D *cont, *contref;					\
  FLGR_Ret ret;								\
									\
  nhb     = flgr2d_create_neighborhood(7,7,1,flgr_get_type_from_string(#dtype), \
				       FLGR_RECT,FLGR_8_CONNEX);	\
									\
  imgsrc  = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  cont    = flgr2d_create_neighbor_box(nhb);				\
  contref = flgr2d_create_neighbor_box(nhb);				\
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
									\
  flgr2d_import_list_data_val_##dtype(contref,pixlst,nhblst,collst,rowlst,16);	\
  flgr2d_get_data_vector(nhb,0,0,contref->center_nhb_val);		\
  flgr2d_get_data_vector(imgsrc,0,0,contref->center_data_val);		\
  contref->center_coord_x = 0;						\
  contref->center_coord_y = 0;						\
				 					\
  ret = flgr2d_get_neighborhood(cont,imgsrc,nhb,0,0);			\
									\
  check_and_display_box2d(contref,cont,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(nhb);							\
  flgr2d_destroy_neighbor_box(cont);					\
  flgr2d_destroy_neighbor_box(contref);					\
									\
  return 1


int testnhb_extract2d_fgUINT8(void) {
  tstNhb_Extract2d(fgUINT8);
}
int testnhb_extract2d_fgUINT16(void) {
  tstNhb_Extract2d(fgUINT16);
}
int testnhb_extract2d_fgUINT32(void) {
  tstNhb_Extract2d(fgUINT32);
}
int testnhb_extract2d_fgINT8(void) {
  tstNhb_Extract2d(fgINT8);
}
int testnhb_extract2d_fgINT16(void) {
  tstNhb_Extract2d(fgINT16);
}
int testnhb_extract2d_fgINT32(void) {
  tstNhb_Extract2d(fgINT32);
}
int testnhb_extract2d_fgFLOAT32(void) {
  tstNhb_Extract2d(fgFLOAT32);
}
int testnhb_extract2d_fgFLOAT64(void) {
  tstNhb_Extract2d(fgFLOAT64);
}





/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr_rec_open types
/////////////////////////////////////////////////////////////////////////
#define tstNhb_Extract2d_spp3(dtype)					\
									\
  dtype rawsrc[]={105,105,105, 115,115,115,  28,28,28,  41,41,41,  41,41,41,  48,48,48,  54,54,54,  57,57,57,  62,62,62,  70,70,70, \
		  72,72,72,  76,76,76,  75,75,75,  76,76,76,  76,76,76,  78,78,78,  75,75,75,  77,77,77,  78,78,78,  76,76,76, \
		  75,75,75,  79,79,79,  77,77,77,  76,76,76,  77,77,77,  73,73,73,  71,71,71,  64,64,64,  62,62,62,  55,55,55, \
		  50,50,50,  44,44,44,  42,42,42,  32,32,32, 123,123,123, 112,112,112, 100,100,100,  88,88,88,  82,82,82,  73,73,73, \
		  73,73,73,  76,76,76,  76,76,76,  81,81,81,  85,85,85,  86,86,86,  90,90,90,  90,90,90,  93,93,93,  92,92,92, \
		  91,91,91,  96,96,96,  96,96,96, 100,100,100,  96,96,96,  98,98,98,  98,98,98,  97,97,97, 102,102,102,  99,99,99, \
		  98,98,98,  96,96,96,  99,99,99, 102,102,102,  98,98,98,  93,93,93, 100,100,100,  99,99,99,  94,94,94,  96,96,96, \
		  94,94,94,  90,90,90,  88,88,88,  87,87,87,  88,88,88,  88,88,88,  85,85,85,  87,87,87,  35,35,35,   5,5,5}; \
									\
  int rowlst[]   = {3,3,3, 3,3,3, 3,3,3, 3,3,3, 4,4,4, 4,4,4, 4,4,4, 4,4,4, 5,5,5, 5,5,5, 5,5,5, 5,5,5, 6,6,6, 6,6,6, 6,6,6, 6,6,6} ; \
  int collst[]   = {3,3,3, 4,4,4, 5,5,5, 6,6,6, 3,3,3, 4,4,4, 5,5,5, 6,6,6, 3,3,3, 4,4,4, 5,5,5, 6,6,6, 3,3,3, 4,4,4, 5,5,5, 6,6,6} ; \
  dtype pixlst[] = {105,105,105, 115,115,115, 28,28,28, 41,41,41,	\
		    72,72,72, 76,76,76, 75,75,75, 76,76,76, 75,75,75,	\
		    79,79,79, 77,77,77, 76,76,76, 50,50,50, 44,44,44,	\
		    42,42,42, 32,32,32};				\
  dtype nhblst[] = {1,1,1, 1,1,1, 1,1,1, 1,1,1, 1,1,1, 1,1,1, 1,1,1,	\
		    1,1,1, 1,1,1, 1,1,1, 1,1,1, 1,1,1, 1,1,1, 1,1,1,	\
		    1,1,1, 1,1,1};					\
									\
									\
  FLGR_Data2D *imgsrc, *nhb;						\
  FLGR_NhbBox2D *cont, *contref;					\
  FLGR_Ret ret;								\
									\
  nhb     = flgr2d_create_neighborhood(7,7,3,flgr_get_type_from_string(#dtype), \
				       FLGR_RECT,FLGR_8_CONNEX);	\
									\
  imgsrc  = flgr2d_create_##dtype(8,10,3,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  cont    = flgr2d_create_neighbor_box(nhb);				\
  contref = flgr2d_create_neighbor_box(nhb);				\
									\
				 					\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
									\
  flgr2d_import_list_data_val_##dtype(contref,pixlst,nhblst,collst,rowlst,16); \
  flgr2d_get_data_vector(nhb,0,0,contref->center_nhb_val);		\
  flgr2d_get_data_vector(imgsrc,0,0,contref->center_data_val);		\
  contref->center_coord_x = 0;						\
  contref->center_coord_y = 0;						\
									\
  ret = flgr2d_get_neighborhood(cont,imgsrc,nhb,0,0);			\
									\
  check_and_display_box2d(contref,cont,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(nhb);							\
  flgr2d_destroy_neighbor_box(cont);					\
  flgr2d_destroy_neighbor_box(contref);					\
									\
  return 1


int testnhb_extract2d_spp3_fgUINT8(void) {
  tstNhb_Extract2d_spp3(fgUINT8);
}
int testnhb_extract2d_spp3_fgUINT16(void) {
  tstNhb_Extract2d_spp3(fgUINT16);
}
int testnhb_extract2d_spp3_fgUINT32(void) {
  tstNhb_Extract2d_spp3(fgUINT32);
}
int testnhb_extract2d_spp3_fgINT8(void) {
  tstNhb_Extract2d_spp3(fgINT8);
}
int testnhb_extract2d_spp3_fgINT16(void) {
  tstNhb_Extract2d_spp3(fgINT16);
}
int testnhb_extract2d_spp3_fgINT32(void) {
  tstNhb_Extract2d_spp3(fgINT32);
}
int testnhb_extract2d_spp3_fgFLOAT32(void) {
  tstNhb_Extract2d_spp3(fgFLOAT32);
}
int testnhb_extract2d_spp3_fgFLOAT64(void) {
  tstNhb_Extract2d_spp3(fgFLOAT64);
}






int testnhb_extract2d_fgBIT(void) {
  fgBIT rawsrc[]={1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
		  1, 0, 0, 1, 0, 0, 0, 0, 0, 0,
		  1, 0, 0, 1, 0, 0, 0, 0, 0, 0,
		  1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
		  0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

  int rowlst[] = {3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6};
  int collst[] = {3,4,5,6,3,4,5,6,3,4,5,6,3,4,5,6};
  fgBIT pixlst[] = {1,1,1,1,1,0,0,1,1,0,0,1,1,1,1,1};
  fgBIT nhblst[] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};	

  FLGR_Data2D *imgsrc, *nhb;
  FLGR_NhbBox2D *cont, *contref;
  FLGR_Ret ret;

  nhb     = flgr2d_create_neighborhood(7, 7,1,FLGR_BIT,FLGR_RECT,FLGR_8_CONNEX);
  imgsrc  = flgr2d_create_pixmap(8,10,1,FLGR_BIT);
  cont    = flgr2d_create_neighbor_box(nhb);
  contref = flgr2d_create_neighbor_box(nhb);


  flgr2d_import_raw_ptr(imgsrc,rawsrc);

  flgr2d_import_list_data_val_fgBIT(contref,pixlst,nhblst,collst,rowlst,16); 
  flgr2d_get_data_vector(nhb,0,0,contref->center_nhb_val);
  flgr2d_get_data_vector(imgsrc,0,0,contref->center_data_val);
  contref->center_coord_x = 0;
  contref->center_coord_y = 0;

  ret = flgr2d_get_neighborhood(cont,imgsrc,nhb,0,0);
  check_and_display_box2d(contref,cont,ret);

  flgr2d_destroy(imgsrc);
  flgr2d_destroy(nhb);
  flgr2d_destroy_neighbor_box(cont);
  flgr2d_destroy_neighbor_box(contref);

  return 1;

}









int testnhb_extract2d_spp3_fgBIT(void) {
  fgBIT rawsrc[]={1,1,1,  1,1,1,  1,1,1,  1,1,1,  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0, 
		  1,1,1,  0,0,0,  0,0,0,  1,1,1,  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0, 
		  1,1,1,  0,0,0,  0,0,0,  1,1,1,  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0, 
		  1,1,1,  1,1,1,  1,1,1,  1,1,1,  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0, 
		  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0, 
		  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0, 
		  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0, 
		  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0,  0,0,0} ;

  int rowlst[] = {3,3,3, 3,3,3, 3,3,3, 3,3,3, 4,4,4, 4,4,4, 4,4,4, 4,4,4, 5,5,5, 5,5,5, 5,5,5, 5,5,5, 6,6,6, 6,6,6, 6,6,6, 6,6,6} ;
  int collst[] = {3,3,3, 4,4,4, 5,5,5, 6,6,6, 3,3,3, 4,4,4, 5,5,5, 6,6,6, 3,3,3, 4,4,4, 5,5,5, 6,6,6, 3,3,3, 4,4,4, 5,5,5, 6,6,6} ;
  fgBIT pixlst[] = {1,1,1, 1,1,1, 1,1,1, 1,1,1, 1,1,1, 0,0,0, 0,0,0, 1,1,1, 
		    1,1,1, 0,0,0, 0,0,0, 1,1,1, 1,1,1, 1,1,1, 1,1,1, 1,1,1} ;
  fgBIT nhblst[] = {1,1,1, 1,1,1, 1,1,1, 1,1,1, 1,1,1, 1,1,1, 1,1,1, 1,1,1, 
		    1,1,1, 1,1,1, 1,1,1, 1,1,1, 1,1,1, 1,1,1, 1,1,1, 1,1,1} ;	

  FLGR_Data2D *imgsrc, *nhb;
  FLGR_NhbBox2D *cont, *contref;
  FLGR_Ret ret;

  nhb     = flgr2d_create_neighborhood(7, 7,3,FLGR_BIT,FLGR_RECT,FLGR_8_CONNEX);
  imgsrc  = flgr2d_create_pixmap(8,10,3,FLGR_BIT);
  cont    = flgr2d_create_neighbor_box(nhb);
  contref = flgr2d_create_neighbor_box(nhb);


  flgr2d_import_raw_ptr(imgsrc,rawsrc);

  flgr2d_import_list_data_val_fgBIT(contref,pixlst,nhblst,collst,rowlst,16); 
  flgr2d_get_data_vector(nhb,0,0,contref->center_nhb_val);
  flgr2d_get_data_vector(imgsrc,0,0,contref->center_data_val);
  contref->center_coord_x = 0;
  contref->center_coord_y = 0;

  ret = flgr2d_get_neighborhood(cont,imgsrc,nhb,0,0);
  check_and_display_box2d(contref,cont,ret);

  flgr2d_destroy(imgsrc);
  flgr2d_destroy(nhb);
  flgr2d_destroy_neighbor_box(cont);
  flgr2d_destroy_neighbor_box(contref);

  return 1;

}
